<script setup>
import { onBeforeMount, onMounted, ref } from 'vue'
import { ElMessage } from 'element-plus'
import { useRouter, useRoute } from 'vue-router'
import Link from "../api/Link.js";
import apiurl from "../api/url.js";
const router = useRouter()
const route = useRoute()

const orderInfo = ref({})
onMounted(async () => {
    await Link(apiurl.get, "GET", {}, { orderId: route.query.id })
        .then((ok) => {
            console.log(ok)
            orderInfo.value = ok
        })
    await Link(apiurl.updateState, "GET", {}, { orderId: route.query.id })
        .then((ok) => {
            console.log(ok)
        })
})



const to_mainview = () => {
    ElMessage({
        showClose: true,
        message: '请稍等，正在跳转主页...',
        type: 'success',
    })
    const message = document.querySelector('.el-message__content')?.parentNode
    //判断提示框的数量   
    if (document.getElementsByClassName('el-message__content').length > 1) {
        setTimeout(function () {
            message.parentNode.removeChild(message);
        }, 100)
    }
    setTimeout(function () {
        router.push("/main")
    }, 500)
}
const to_myorder = () => {
    ElMessage({
        showClose: true,
        message: '请稍等，正在跳转我的订单...',
        type: 'success',
    })
    const message = document.querySelector('.el-message__content')?.parentNode
    //判断提示框的数量   
    if (document.getElementsByClassName('el-message__content').length > 1) {
        setTimeout(function () {
            message.parentNode.removeChild(message);
        }, 100)
    }
    if (orderInfo.value.type != 5) {
        setTimeout(function () {
            router.push({
                path: '/myorder',
                query: {
                    title: "全部车票订单",
                    type: 7
                }
            })
        }, 500)
    } else {
        setTimeout(function () {
            router.push({
                path: '/myorder',
                query: {
                    title: "酒店订单",
                    type: 5
                }
            })
        }, 500)
    }

}
</script>


<template>
    <div class="xtx-pay-page">
        <div class="container">
            <!-- 支付结果 -->
            <div class="pay-result">
                <!-- 路由参数获取到的是字符串而不是布尔值 -->
                <p class="tit">支付{{ $route.query.payResult === 'true' ? '成功' : '失败' }}</p>
                <span class="iconfont green" v-if="$route.query.payResult === 'true'">
                    <p>支付方式：<span>支付宝</span></p>
                    <p>支付金额：<span>¥{{ orderInfo.payPrice }}</span></p>
                </span>
                <span class="iconfont  red" v-else>
                    <p class="tip ">请尝试重新支付，或者检查网络设置</p>
                    <p>支付方式：<span>支付宝</span></p>
                    <p>支付金额：<span>¥0</span></p>
                </span>

                <div class="btn">
                    <el-button type="primary" style="margin-right:20px" @click="to_myorder">查看订单</el-button>
                    <el-button @click="to_mainview">进入首页</el-button>
                </div>
                <p class="alert">
                    <span class="iconfont icon-tip"></span>
                    温馨提示：途路旅游网不会以订单异常、系统升级为由要求您点击任何网址链接进行退款操作，保护资产、谨慎操作。
                </p>
            </div>
        </div>
    </div>
</template>

<style scoped lang="scss">
.pay-result {
    padding: 100px 0;
    background: #fff;
    text-align: center;
    margin-top: 20px;

    >.iconfont {
        font-size: 100px;
    }

    .green {
        color: #1dc779;
    }

    .red {
        color: red;
    }

    .tit {
        font-size: 24px;
    }

    .tip {
        color: #999;
    }

    p {
        line-height: 40px;
        font-size: 16px;
    }

    .btn {
        margin-top: 50px;
    }

    .alert {
        font-size: 12px;
        color: #999;
        margin-top: 50px;
    }
}
</style>